﻿using Acme.SmartWMS.DataBasic;
using Acme.SmartWMS.Location.StorageLocationService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.SmartWMS.Location
{
    public class StorageLocationAppService: ApplicationService, IStorageLocationAppService
    {
        private readonly IRepository<StorageLocation> _repository;

        public StorageLocationAppService(IRepository<StorageLocation> repository)
        {
            _repository = repository;
        }

        /// <summary>
        /// 查询储位数据
        /// </summary>
        /// <param name="code"></param>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<PagedResult<StorageLocation>> GetPageStorage(string? code,int isDisabled, int limit,int page)
        {
            PagedResult<StorageLocation> result = new PagedResult<StorageLocation>();
            var items = (await _repository.GetListAsync(x => (string.IsNullOrEmpty(code) || x.LocationCode.Contains(code))&&(isDisabled == 0||x.IsDisabled == isDisabled))).AsQueryable();
            result.RowCount = items.Count();
            result.PageCount = (int)Math.Ceiling(items.Count() * 1.0 / limit);
            result.Queryable = items.Skip((page - 1) * limit).Take(limit).AsQueryable();
            return result;
        }
    }
}
